﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Catering_Rules;
using Catering.View_Operaction;

namespace Catering.UCPanle
{
    public partial class UCSearchToolRCJK : System.Web.UI.UserControl
    {
        private string AREAID = "";
        private string CLASSID = "";
        private string Day = "";
        FromRecords frRules = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //TextBox2.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-M'})");
                if (DropDownList1.SelectedItem != null)
                {
                    if (DropDownList1.SelectedItem.Value.Equals("Day"))
                    {
                        TextBox2.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-MM-dd'})");
                    }
                    else if (DropDownList1.SelectedItem.Value.Equals("Month"))
                    {
                        TextBox2.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-M'})");
                    }
                }
                loadPage();
            }
        }
        private void loadPage()
        {
            if (Session["User"] != null)
            {
                string userid = Session["PersonnelID"].ToString();
                int companyid = 0;
                int groupid = 0;
                int classid = 0;
                bool isAdmin = false;
                Bind_Data_to_Controls.GetCompanyByCurrentUser(userid, out companyid, out groupid, out classid, out isAdmin);
                Bind_Data_to_Controls.Bind_Area_ddl(ddl_Area, isAdmin, groupid, companyid);
                Bind_Data_to_Controls.Bind_Class_ddl(ddl_Area.SelectedItem, ddl_class, isAdmin, classid);
            }
        }

        /// <summary>
        /// 获取作业区ID
        /// </summary>
        /// <returns></returns>
        public string GetDDL_Area()
        {
            if (ddl_Area.SelectedItem != null)
            {
                AREAID = ddl_Area.SelectedItem.Value;
            }
            return AREAID;
        }
        /// <summary>
        /// 获取班组ID
        /// </summary>
        /// <returns></returns>
        public string GetDDL_Class()
        {
            if (ddl_class.SelectedItem != null)
            {
                CLASSID = ddl_class.SelectedItem.Value;
            }
            return CLASSID;
        }

        /// <summary>
        /// 返回已选择时间
        /// </summary>
        /// <returns></returns>
        public DateTime GetDateTime()
        {
            DateTime dTime = DateTime.Parse("1949-10-01");
            if (!string.IsNullOrEmpty(TextBox2.Text))
            {
                string str = TextBox2.Text;
                DateTime.TryParse(str, out dTime);
            }
            return dTime;
        }

        public void InitDateTime(string datetime, string datetype)
        {
            DropDownList1.SelectedValue = datetype;
            TextBox2.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-MM-dd'})");
            TextBox2.Text = datetime;
        }

        /// <summary>
        /// 获取时间类型
        /// </summary>
        /// <returns></returns>
        public string GetTimeType()
        {
            string str = "";
            if (DropDownList1.SelectedItem != null)
            {
                str = DropDownList1.SelectedItem.Value;
            }
            return str;
        }

        protected void ddl_Area_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddl_Area.SelectedItem != null)
            {
                Bind_Data_to_Controls.Bind_Class_ddl(ddl_Area.SelectedItem, ddl_class);
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedItem != null)
            {
                if (DropDownList1.SelectedItem.Value.Equals("Day"))
                {
                    TextBox2.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-MM-dd'})");
                    TextBox2.Text = "";
                }
                else if (DropDownList1.SelectedItem.Value.Equals("Month"))
                {
                    TextBox2.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-M'})");
                    TextBox2.Text = "";
                }
            }

        }
    }
}